package cn.elwy.rcp.kit.builder.maven;

import java.io.File;
import java.io.FilenameFilter;

import org.apache.commons.io.filefilter.FileFilterUtils;

public class DeleteLastUpdatedHandler {

  private static final String FILE_SUFFIX = "lastUpdated";

  public void delFileRecr(File[] dirs, File[] files) {
    if (dirs != null && dirs.length > 0) {
      for (File dir : dirs) {
        File[] childDir = dir.listFiles((FilenameFilter) FileFilterUtils.directoryFileFilter());
        File[] childFiles = dir.listFiles((FilenameFilter) FileFilterUtils.suffixFileFilter(FILE_SUFFIX));
        delFileRecr(childDir, childFiles);
      }
    }
    if (files != null && files.length > 0) {
      for (File file : files) {
        if (file.delete()) {
          out("删除文件: [" + file.getAbsolutePath() + "]");
        }
      }
    }
  }

  public void out(String message) {
    System.out.println(message);
  }

}
